<?php
	date_default_timezone_set('PRC');
	$root = dirname(__FILE__);
	$root = str_replace('\\tool', '/', $root);
	define('ROOT', $root);
	
	function create_file($path,$content){
		$fp = fopen($path,'w');
		fwrite($fp, $content);
		fclose($fp);
	}
	
	function get_con(){
		global $con;
		if($con!=null)
			return $con;
		$db_cfg = require_once ROOT.'/data/config.inc.php';
		$cfg = parse_url($db_cfg['DB_CONFIG']);
		$charset = 'utf8';
		$dbname = str_replace('/', '', $cfg['path']);
		$con = mysql_connect($cfg['host']. ':' .$cfg['port'], $cfg['user'], $cfg['pass'], true);
		mysql_query("SET character_set_connection=$charset, character_set_results=$charset, character_set_client=binary", $con);
		mysql_select_db($dbname, $con);
		return $con;
	}
	
	function getAll($sql){
		$con = get_con();
		$result = mysql_query($sql);
		if ($result !== false)
        {
            $arr = array();
            while ($row = mysql_fetch_assoc($result)){
                $arr[] = $row;
            }
			mysql_close($con);
            return $arr;
        }else{
			mysql_close($con);
            return false;
        }
	}